{layout name="../../admin/view/layout/main" /}
{:breadcrumb(['UI 示例:example/layout/index', '常用插件:example/plugin/index', '表单向导'])}
<div class="row">

    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">

          <form action="#!" class="lyear-guide-box" data-navigateable="true">
            <ul class="nav nav-step">
              <li class="nav-item">
                <span>步骤一</span>
                <a class="nav-link active" data-toggle="tab" href="#step-1"></a>
              </li>

              <li class="nav-item">
                <span>步骤三</span>
                <a class="nav-link" data-toggle="tab" href="#step-2"></a>
              </li>

              <li class="nav-item">
                <span>步骤四</span>
                <a class="nav-link" data-toggle="tab" href="#step-3"></a>
              </li>

              <li class="nav-item">
                <span>步骤五</span>
                <a class="nav-link" data-toggle="tab" href="#step-4"></a>
              </li>
            </ul>
            <!--对应内容-->
            <div class="nav-step-content">
              <div class="nav-step-pane d-none active" id="step-1"  data-provide="validation">
                <div class="form-group">
                  <label>姓名</label>
                  <input class="form-control" type="text" id="username" required />
                </div>
              </div>

              <div class="nav-step-pane d-none" id="step-2" data-provide="validation">
                <div class="form-group">
                  <label>邮箱地址</label>
                  <input class="form-control" type="text" id="email" required />
                </div>
              </div>

              <div class="nav-step-pane d-none" id="step-3" data-provide="validation">
                <div class="form-group">
                  <label>设置密码</label>
                  <input class="form-control" type="password" id="password" required />
                </div>
              </div>

              <div class="nav-step-pane d-none" id="step-4">
                <div class="form-group">
                  <label>备注</label>
                  <input class="form-control" type="text" id="remark" />
                </div>
              </div>
            </div>
            <!--End 对应内容-->
            <hr>
            <div class="d-flex justify-content-between">
              <button class="btn btn-secondary disabled" data-wizard="prev" type="button">上一步</button>
              <button class="btn btn-secondary" data-wizard="next" type="button">下一步</button>
              <button class="btn btn-primary d-none" data-wizard="finish">完成</button>
            </div>
          </form>

        </div>
      </div>
    </div>

  </div>

  <script type="text/javascript">
    $(document).ready(function() {
        var guideObj = $('.lyear-guide-box');
        var nav_item = guideObj.find('.nav-item');
        var tab_pane = guideObj.find('.nav-step-pane');
        
        guideObj.bootstrapWizard({
            'tabClass': 'nav-step',
            'nextSelector': '[data-wizard="next"]',
            'previousSelector': '[data-wizard="prev"]',
            'finishSelector': '[data-wizard="finish"]',
            'onTabClick': function(e, t, i) {
                // data-navigateable='true'允许用户直接点击步骤项，false则只能通过按钮
                if ( !$('.lyear-guide-box').is('[data-navigateable="true"]') ) {
                    return false;
                }
            },
            'onTabShow': function(e, t, i) {
                t.children(":gt(" + i + ").complete").removeClass("complete");
                t.children(":lt(" + i + "):not(.complete)").addClass("complete");
            },
            'onNext': function(tab, navigation, index){
                var current_index = guideObj.bootstrapWizard('currentIndex');
                var curr_tab      = tab_pane.eq(current_index);
                
                var validator_selector = '[data-provide="validation"]';
                var validator = curr_tab.find(validator_selector).addBack(validator_selector);
                if (validator.length) {
                    var forms = validator.find('input, select, textarea');
                    var validation = true;
                    forms.each(function() {
                        if (this.checkValidity() === false) {
                            guideObj.addClass('was-validated');
                            validation = false;
                        } else {
                            guideObj.removeClass('was-validated');
                        }
                    });
                    if (!validation) {
                        guideObj.addClass('was-validated');
                        return false;
                    }
                }
            },
            'onPrevious': function(){
            },
            'onFinish': function(e, t, i) {
                var nav = nav_item.eq(i);
                
                nav.addClass('complete').find('a.nav-link').removeClass('active');
                return false; // 这里为了演示效果，阻止其继续
            }
        });
    });
    </script>